{% extends "base.html" %}

{% load shop_currency %}
{% load url_parameters %}

{% block content %}

<h2>{% block title %}Your Orders{% endblock %}</h2>

{% if not orders.object_list %}
    <p>You have not made any orders yet. See all of our <a href="{% url shop.views.product.list %}">products</a>.</p>
{% else %}
    <table id="order-listing">
        <thead>
            <tr>
                <th>ID#</th>
                <th class="order-price">Price</th>
                <th>Placed on</th>
                <th>Status</th>
                <th></th>
            </tr>
        </thead>
        <tbody class="order_item">
        {% for order in orders.object_list %}
            <tr>
                <td>{{ order.id }}</td>
                <td class="order-price">{{ order.total_price|currency }}</td>
                <td>{{ order.created|date:"j.n.Y G:i" }}</td>
                <td>
                    {% if order.status == 'W' %}<span class="order-notpaid-text">The order is awaiting payment.</span>{% endif %}
                    {% if order.status == 'P' %}<span class="order-processed-text">Payment received. Your delivery is being processed.</span>{% endif %}
                    {% if order.status == 'D' %}<span class="order-shipped-text">The order has been shipped on {{ order.shipped|date:"j.n.Y G:i" }}.</span>{% endif %}
                </td>
                <td>
                    {% if order.status == 'W' %}
                        <a href="{% url shop.views.checkout.show_payment order.id %}">Continue to checkout</a>
                    {% else %}
                        <a href="{% url shop.views.orders.show_completed_order order.id %}">Show</a>
                    {% endif %}
                </td>
            </tr>
        {%  endfor %}
        </tbody>
    </table>
{% endif %}

{% if orders.paginator.num_pages > 1 %}
<div class="pagination">
    {% if orders.has_previous %}
        <span class="prev"><a href="{% add_get_parameter page=orders.previous_page_number %}" title="go to page {{ orders.previous_page_number }}">prev</a></span>
    {% endif %}

    {% for page in orders.paginator.page_range %}
        {% if page == orders.number %}
            <span class="current">{{ page }}</span>
        {% else %}
            <span><a href="{% add_get_parameter page=page %}" title="go to page {{ page }}">{{ page }}</a></span>
        {% endif %}
    {% endfor %}

    {% if orders.has_next %}
        <span class="next"><a href="{% add_get_parameter page=orders.next_page_number %}" title="go to page {{ orders.next_page_number }}">next</a></span>
    {% endif %}
</div>
{% endif %}

{% endblock %}
